package com.ricky.hospital_cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ricky.hosp.model.cmn.Dict;
import com.ricky.hosp.vo.cmn.DictEeVo;
import com.ricky.hospital_cmn.mapper.DictMapper;
import com.ricky.hospital_cmn.service.DictService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class DictListener extends AnalysisEventListener<DictEeVo> {
    public static DictListener dictListener;

    @Autowired
    private DictMapper dictMapper;

    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo,dict);
        dictListener.dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
    @PostConstruct
    public void init(){
        dictListener = this;
        dictListener.dictMapper = this.dictMapper;

    }
}
